package com.zy.springboot.controller;

import com.zy.springboot.bo.UserBo;
import com.zy.springboot.service.UserService;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhaoyi
 * @date 2021/7/29 15:01
 * <p>
 * https://www.cnblogs.com/three-fighter/p/12346184.html
 */

@Api(value = "用户API")
@Slf4j
@RestController
@RequestMapping("/user/")
public class UserApi {

    @Resource
    private UserService userService;

    @ApiOperation(value = "通过id获取用户", notes = "PathVariable")
    @GetMapping("{id}")
    public String get(@PathVariable("id") @ApiParam(name = "id", value = "用户id", required = true) String id) {
        return userService.get(id);
    }

    @ApiOperation(
            value = "新增",
            notes = "新增用户",
            response = UserBo.class
    )
    @PostMapping("addUser")
    @ResponseBody
    public UserBo addUser(@RequestBody UserBo user) {
        return user;
    }

    /**
     * paramType	参数放在哪个地方
     *      query --> 请求参数的获取：@RequestParam
     *      header --> 请求参数的获取：@RequestHeader
     *      path（用于restful接口）--> 请求参数的获取：@PathVariable
     *      body（请求体）--> @RequestBody User user
     *      form（普通表单提交）
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "手机号",
                    required = true, paramType = "query",dataType="Integer",
                    defaultValue="13766662626"),
            @ApiImplicitParam(name = "password", value = "密码", required = true),
    })
    @PostMapping("/login")
    public UserBo login(@RequestParam Integer mobile, @RequestParam String password) {
        return new UserBo();
    }


}
